표준 제어 흐름은 예측 가능한 진행 방식입니다. 프로그램 카운터는 순차적 논리나 명시적인 점프에 따라 주소 $a_k$에서 $a_{k+1}$로 이동합니다. 그러나, 예외적 제어 흐름 (ECF) 이러한 정상적인 흐름 밖에서 발생하는 '갑작스러운' 전환을 나타냅니다.
1. 수학적 모델
프로세서 실행은 각각 $a_k$가 명령어 $I_k$에 해당하는 수열 $a_0, a_1, \dots, a_{n-1}$입니다. ECF는 프로세서 상태의 변화— 이벤트—가 응용 프로그램의 즉각적인 코드 경로에 없는 특수 처리기로 점프를 유도할 때 이 연결이 끊깁니다.
2. 구현 수준
ECF는 하드웨어와 소프트웨어 사이의 간격을 메웁니다. 이는 하드웨어 수준의 예외 (오류, 인터럽트)에서 운영체제 수준의 컨텍스트 스위칭 및 시그널까지 다양합니다.
3. '갑작스러운' 현실
사용자가 Ctrl+C 또는 디스크 접근을 요청하는 시스템 호출이라도, ECF는 CPU가 다른 '세계'—커널—로 점프하도록 강제하여 시스템이 동적 상태 변화에 계속 반응할 수 있도록 보장합니다.
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
Practice Problem 8.1: Given Process A(1-3), B(2-5), and C(4-6), which pair is NOT concurrent?
Processes A and B
Processes A and C
Processes B and C
All processes are concurrent.
✅ Correct!
Processes A(1-3) and C(4-6) do not overlap in time; A finishes before C starts.❌ Incorrect
Concurrency requires a time overlap. A(1-3) and B(2-5) overlap at time 2. B(2-5) and C(4-6) overlap at time 4.QUESTION 2
Which function is called once but returns only if there is an error?
fork()
exit()
execve()
waitpid()
✅ Correct!
execve() overwrites the current process image; if successful, it never returns to the caller.❌ Incorrect
fork() returns twice. exit() never returns. waitpid() returns when a child changes state.QUESTION 3
In the mathematical model of control flow, what triggers an 'exceptional' transition?
A standard sequential instruction Iₖ₊₁
An explicit loop or function call
A change in processor state (Event)
The end of the program counter
✅ Correct!
ECF is defined by transitions triggered by events external or internal to the instruction stream, not normal logic.❌ Incorrect
Standard transitions (loops, calls) are part of normal control flow, not exceptional.QUESTION 4
Which function behavior matches: 'Called once, returns either a pointer or NULL'?
getenv()
fork()
exit()
longjmp()
✅ Correct!
getenv() searches for an environment variable and returns its pointer or NULL if not found.❌ Incorrect
fork() returns a PID/0. exit() returns nothing. longjmp() returns to setjmp().QUESTION 5
If a process receives a signal of type k while another signal of type k is pending, what happens?
The signal is queued.
The signal is discarded.
The kernel crashes.
The handler is interrupted by the new signal.
✅ Correct!
Signals are non-queuing; if a signal is already pending, subsequent instances of that same signal are dropped.❌ Incorrect
Signals of the same type do not queue in standard Unix systems.Case Study: Analyzing Execution Flow in global-waitprob1.c
Synchronization and ECF Transitions
Consider a program where a parent process calls fork() to create a child, and the parent immediately calls waitpid() to reap it. Analyze the resulting control flow divergence and convergence.
Q
How many output lines does this program generate and what is the ordering principle?
Solution:
The program generates 2 output lines. The ordering is strictly deterministic: the child's output must appear before the parent's final output because waitpid() acts as a synchronization barrier, forcing the parent's sequential flow to pause until the child's exceptional exit state is processed.
The program generates 2 output lines. The ordering is strictly deterministic: the child's output must appear before the parent's final output because waitpid() acts as a synchronization barrier, forcing the parent's sequential flow to pause until the child's exceptional exit state is processed.
Q
Required Output Task: Analyze the global-waitprob1.c execution flow (approx. 200 words).
Solution:
The execution of global-waitprob1.c serves as a textbook illustration of Exceptional Control Flow through process management. Upon reaching the fork() call at address a_k, the system state undergoes a profound transition. The operating system creates a duplicate logical control flow—the child—which begins its own sequence starting from a duplicate set of registers and address space. This creates a divergence where two distinct sequences (a_0...a_n) coexist. The parent process immediately encounters the waitpid() system call, which is a 'Trap' class exception. This call effectively places the parent's sequential instruction stream in a suspended state, waiting for a hardware-triggered event: the child's termination. In this moment, the child process executes its unique path independently. When the child calls exit(), an exceptional event occurs that notifies the kernel. The kernel then context-switches back to the parent, resolving the waitpid() block. This synchronization barrier ensures that the child's logical flow is 'reaped' before the parent proceeds. Ultimately, the two flows, though briefly concurrent and independent, are reconciled by the OS to ensure predictable output, proving that ECF is not chaotic but a highly structured collaboration between the hardware, kernel, and application logic.
The execution of global-waitprob1.c serves as a textbook illustration of Exceptional Control Flow through process management. Upon reaching the fork() call at address a_k, the system state undergoes a profound transition. The operating system creates a duplicate logical control flow—the child—which begins its own sequence starting from a duplicate set of registers and address space. This creates a divergence where two distinct sequences (a_0...a_n) coexist. The parent process immediately encounters the waitpid() system call, which is a 'Trap' class exception. This call effectively places the parent's sequential instruction stream in a suspended state, waiting for a hardware-triggered event: the child's termination. In this moment, the child process executes its unique path independently. When the child calls exit(), an exceptional event occurs that notifies the kernel. The kernel then context-switches back to the parent, resolving the waitpid() block. This synchronization barrier ensures that the child's logical flow is 'reaped' before the parent proceeds. Ultimately, the two flows, though briefly concurrent and independent, are reconciled by the OS to ensure predictable output, proving that ECF is not chaotic but a highly structured collaboration between the hardware, kernel, and application logic.